public class TestSubstring {
    public static void main(String[] args) {
        int num = getStringCount("adsJKJjava3K21Af,javaaAD134F13241javad134134s141javafaAAFDF", "java");
        System.out.println("java在字符串中出现的次数：" + num);
    }
    //获取一个字符串，查找这个字符串出现的次数;
    public static int getStringCount(String str, String key) {
        int count = 0;
        int index = 0;
        int num = str.indexOf(key);
        while ((index = str.indexOf(key,index)) != -1){
			index = index +key.length();
			count++;
		}
        return count;
    }

}
